$(function(){

    var code;
    var tel;
    
    /*用户点击获取验证码*/
    $(".information-obtain").on("click",function(){

        var re = /^1\d{10}$/;
        var tel_click = $("input[type='tel']").val();
        tel = tel_click;
        if(re.test(tel)){
            $.ajax({
                type: "post",
                url: "/dingding-web/comActAction!getTelePhoneCode.action",
                dataType: "jsonp",
                async: false,
                jsonp: "callback",
                jsonpCallback: "success_jsonp",
                data:{
                    telephone:tel
                },
                success: function(data){
                	console.log(data);
                    if(data.responseBody == "error"){
                        alert("获取验证码失败");
                    }
                }
            });
            
            //获取验证码之后用户在一分钟之内不能再次点击获取，并实现一分钟倒计时，之后才能继续获取 
            var count = 60;
            var countdown = setInterval(CountDown, 1000);
            function CountDown() {
                $(".information-hq").attr("disabled", true);
                $(".information-hq").text(count + "s");
                if (count == 0) {
                    $(".information-hq").text("获取").removeAttr("disabled");
                    clearInterval(countdown);
                }
                count--;
            }
            
        }
        else{
            alert('请输入正确的手机号码');
        }
    });
        
    /*用户点击登陆前往对应的活动主页*/
    $(".login-go").on("click",function(){
        tel = $("input[type='tel']").val();
        code = $("input[type='number']").val();
        if(tel && code){
        	
        	$.ajax({
                type: "post",
                url: "/dingding-web/wechatOrderAction!userLogin.action",
                dataType: "jsonp",
                async: false,
                jsonp: "callback",
                jsonpCallback: "success_jsonp",
                data:{
                    telephone: tel,
                    messageCode: code
                },
                success: function(data){
                	console.log(data);
                	if(data.code != 200) {
                		alert(data.errorMessage);
                	}
                	else {
                		window.location.href = 'driver-order.html';
                	}
                	
                }
           });
           
        }else{
            alert('请输入手机号或验证码');
        }
        
    });

    //input获取焦点时，law隐藏
    $("input").focus(function(){
        $(".law").css('display','none');
    });
    
    //input获取焦点时，law重现
    $("input").blur(function(){
        $(".law").css('display','block');
    });
});